import random

# reading & cleaning the data
with open(r"C:\Users\86189\Downloads\week-8-session-1-main\week-8-session-1-main\activity-1-random\names.txt", encoding="utf-8") as f:
    names = f.readlines()
names = [ name.strip() for name in names ]


'''
names is a list of 1000 names - each name is 2 words long (in format: firstname surname).

You have three tasks:

Task 1:

Ask the user to enter a number, and pick that many random names out of the list.


Task 2:

Create 10 new random names by picking 10 random firstnames and combining them with 10 random surnames.

Task 3:

Shuffle the list and create 250 teams of 4 random people.
Hint: use a list-of-lists to store the teams.

'''

#Task 1

num = int(input("请输入想生成几个随机数："))

picked = random.sample(names, num)

for name in picked:
    print(name)

#Task 2

# 2. 把 1000 个名字拆成“名池”和“姓池”
first_names = [name.split()[0] for name in names]   # 所有名
last_names  = [name.split()[1] for name in names]   # 所有姓

# 3. 不放回地随机抽 10 个名 + 10 个姓
rand_first = random.sample(first_names, 10)
rand_last  = random.sample(last_names,  10)

# 4. 一一配对，拼成 10 个新名字
new_names = [f"{f} {l}" for f, l in zip(rand_first, rand_last)]

# 5. 打印结果
print(new_names)

#Task 3

random.shuffle(names)

teams = []

for i in range(0, 1000, 4):
    team = names[i:i + 4]
    teams.append(team)

print(teams)